package com.freewater.springboot.demo.aop.advice.order.diffadvicetype;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;


@Aspect
public class Aspect1 {

    @Pointcut("execution(* com.freewater.springboot.demo.aop.advice.order.SomeBusiness+.*(..))")
    public void someBusiness() {

    }

    @Before("someBusiness() && args(data)")
    public void beforeAdvice(String data) {
        System.out.println("beforeAdvice data: " + data);
    }

    @After("someBusiness() && args(data)")
    public void afterAdvice(String data) {
        System.out.println("afterAdvice data: " + data);
    }

    @AfterReturning("someBusiness() && args(data)")
    public void afterReturning(String data) {
        System.out.println("afterReturning data: " + data);
    }

    @AfterThrowing("someBusiness() && args(data)")
    public void afterThrowing(String data) {
        System.out.println("afterThrowing data: " + data);
    }

    @Around("someBusiness() && args(data)")
    public Object aroundAdvice(ProceedingJoinPoint jp, String data) {
        try {
            System.out.println("aroundAdvice before, data: " + data);
            Object result = jp.proceed(new Object[]{data});
            System.out.println("aroundAdvice after, data: " + data);
            return result;
        } catch (Throwable e) {
            System.out.println("business method error: " + e.getMessage());
            return "error";
        }
    }
}
